﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SmartWMS.Common.Enum;
using SmartWMS.Common.Extensions;
using SmartWMS.Common.ResponseOutput;
using SmartWMS.Domain.Base;
using SmartWMS.Domain.BusinessManage;
using SmartWMS.EntityFramework;
using SmartWMS.Server.BusinessServer.ProcureMentServices;
using SmartWMS.Server.BusinessServer.ProcureMentServices.Dto;

namespace SmartWMS.API.Controllers.BusinessMange
{
    /// <summary>
    /// 采购管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = "Business")]

    public class ProcureMentController : ControllerBase
    {
        private readonly IProcureMentService _procureMentService;
        public ProcureMentController(IProcureMentService procureMentService)
        {
            _procureMentService = procureMentService;
        }

        /// <summary>
        /// 采购管理列表
        /// </summary>
        /// <param name="select"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<Response<List<ProcureMentDtos>>> CatProcureMentList(ProcureSelect select)
        {
            var result = _procureMentService.CatProcureMentList(select);
            return result;
        }

        /// <summary>
        /// 绑定枚举（采购状态）
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public object GetProcureStatus()
        {
            List<object> list = new List<object>();
            foreach (var item in Enum.GetValues<Domain.Base.ProcurementState>())
            {
                list.Add(new { value = (int)item, label = item.ToString() });
            }
            return list;
        }

        /// <summary>
        /// 采购管理添加
        /// </summary>
        /// <param name="procureMentDto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public Task<Response<bool>> AddProcureMent(ProcureMentDtos procureMentDto)
        {
            var result = _procureMentService.AddProcureMent(procureMentDto);
            return result;
        }

        /// <summary>
        /// 销售单号列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public Task<Response<List<SalesManagementDto>>> GetSalesCodeList()
        {
            var result = _procureMentService.GetSalesCodeList();
            return result;
        }

        /// <summary>
        /// 根据销售单号获取销售单信息
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public Task<Response<SalesManagementDto>> GetSalesManagementByCode(string? code)
        {
            var result = _procureMentService.GetSalesManagementByCode(code);
            return result;
        }

        /// <summary>
        /// 根据采购单号获取采购单信息
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public Task<Response<ProcureMentDtos>> GetProcureManagementByCode(string? code)
        {
            var result = _procureMentService.GetProcureManagementByCode(code);
            return result;
        }

        /// <summary>
        ///  删除采购管理
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<Response<bool>> DeleteProcureMent(ProcureSelect dto)
        {
            var result = _procureMentService.DeleteProcureMent(dto);
            return result;
        }

        /// <summary>
        /// 批量删除采购管理
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<Response<bool>> DeleteProcureMentList(List<ProcureSelect> dto)
        {
            var result = _procureMentService.DeleteProcureMentList(dto);
            return result;
        }

        /// <summary>
        /// 编辑采购管理
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public Task<Response<bool>> UpdateProcureMent(ProcureMentDtos dto)
        {
            var result = _procureMentService.UpdateProcureMent(dto);
            return result;
        }

        /// <summary>
        /// 采购入账
        /// </summary>
        /// <param name="code"></param>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public Task<Response<bool>> ProcureInAccount(InAccountDto? dto)
        {
            var result = _procureMentService.ProcureInAccount(dto);
            return result;
        }

        /// <summary>
        ///  采购退货
        /// </summary>
        /// <param name="procuremenReturns"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<Response<bool>> ProcureReturn(ProcureReturnDto info)
        {
            var result = _procureMentService.ProcureReturn(info);
            return result;
        }
    }
}
